function creardatatable() {

    
	Context.StatusFormatter = function(cell, row, col, data){
        var combo = Context.VigenciaCatalog;
        for (var i = 0; i < combo.length; i++) {
            if (data == combo[i].value) {
                cell.innerHTML = combo[i].label;
                return;
            }
        }
    };
    
	var detalleFormatter = function(cell, row, col, data) {
		if(data == true || data == "true"){
			cell.innerHTML = '<div style="text-align: center"><input type="image" src="' + Z.zuictx
				+ '/edit.gif" value="Detalle" size="21,21" style="width:21px;height:21px"  border="0" alt="Detalle" onclick="return false;"/></div>';
		}
	};

	var myColumnDefs = [ {
		key : "folio",
		label : "FOLIO"
	}, {
		key : "status",
		label : "ESTATUS",
		formatter: Context.StatusFormatter
	}, {
		key : "consignor",
		label : "CONSIGNANTE"			
	}, {
		key : "consignee",
		label : "CONSIGNATARIO"
	}, {
		key : "pdf",
		label : "DETALLE",
        formatter: detalleFormatter
	}];

	try {
		var config = {};
		config.URL = Context.Busqueda;
		config.FIELDS = [ "folio", "status", "consignor", "consignee", "pdf", "modificado", "eliminar", "nuevo" ];
		config.COLUMNS = myColumnDefs;
		config.DATATABLE_DIV = "datatable";
		config.PAGINATOR_DIV = "paginator";
		config.TOTAL_REGISTROS_DIV = "totalregistros";
		config.ROW_PER_PAGE = 10;

		Context.table = new Z.Table(config);
		myDataTable = Context.table.getDatatable();
		
		myDataTable.subscribe("buttonClickEvent", function(oArgs) {

			var target = oArgs.target;
			var record = this.getRecord(target);
			if (target.value == "Detalle") {
				detalle(record);
			}  else {
				alert("buttonClickEvent value desconocido: " + target.value);
			}
			return false;
		});
		
		myDataTable.subscribe("rowClickEvent", function(oArgs) {
			var target = oArgs.target;
			var record = this.getRecord(target);
			if (target.value == "Detalle") {
			}
			else{
			try {
				var f = document.getElementById("detalleForm");
				f.elements['idCert'].value = record.getData('folio')
				var callback = new Z.JsonCall();
				callback.exito = function(data) {
					
					myDataTableD.insertar(data.ResultSet.Result);
					
					
				};
				callback.fallo = function(messages) {
					alert("error")
				};
				Context.tableD.clear();
				
				Z.ShowWait();
				Y.util.Connect.setForm(f);
				var request = Y.util.Connect.asyncRequest('POST', Context.Mercancia,
						callback);

			} catch (e) {
				alert("busqueda: " + e + e.description);
			}
			}
		});
		
		

	} catch (e) {
		alert(e);
	}

	
	myDataTable.insertar = function(rows){
        try {
            if (Y.lang.isArray(rows)) {
                for (var j = 0; j < rows.length; j++) {
                    var m = rows[j];
                    try {
                        var oData = {};
                        
                        oData['folio'] = m.folio;
                        oData['status'] = m.status;
                        oData['consignor'] = m.consignor;
                        oData['consignee'] = m.consignee;
                        oData['pdf'] = m.pdf;
                        oData['modificado'] = false;
                        myDataTable.addRow(oData, myDataTable.getRecordSet().getLength());
                        
                    } catch (e) {
                        alert("insertar:" + e.description+" "+x.message);
                    }
                }
                
            }
        } catch (x) {
            alert("insertar: " + x.description +" "+x.message);
            return false;
        }
    };
	
}

function creardatatableDetalle() {

	var detalleFormatter = function(cell, row, col, data) {
		cell.innerHTML = '<div style="text-align: center"><input type="image" src="' + Z.zuictx
				+ '/edit.gif" value="Detalle" size="21,21" style="width:21px;height:21px"  border="0" alt="Detalle" onclick="return false;"/></div>';
	};

	var myColumnDefs = [ {
		key : "sequence",
		label : "NO. SECUENCIAL"
	}, {
		key : "description",
		label : "DESCRIPTION"
	}, {
		key : "commonname",
		label : "NOMBRE COMUN"			
	}, {
		key : "scientificname",
		label : "NOM. CIENTIFICO"
	}/*, {
		key : "modificado",
		label : "DETALLE",
        formatter: detalleFormatter
	}*/];

	try {
		var config = {};
		config.URL = Context.Busqueda;
		config.FIELDS = [ "sequence", "description", "commonname", "scientificname", "modificado", "eliminar", "nuevo" ];
		config.COLUMNS = myColumnDefs;
		config.DATATABLE_DIV = "datatableD";
		config.PAGINATOR_DIV = "paginatorD";
		config.TOTAL_REGISTROS_DIV = "totalregistrosD";
		config.ROW_PER_PAGE = 10;

		Context.tableD = new Z.Table(config);
		
		myDataTableD = Context.tableD.getDatatable();
		
		myDataTableD.subscribe("buttonClickEvent", function(oArgs) {

			var target = oArgs.target;
			var record = this.getRecord(target);
			if (target.value == "Detalle") {
				Context.dialog2.setHeader("Detalle Certificado");
				Context.dialog2.show();
			}  else {
				alert("buttonClickEvent value desconocido: " + target.value);
			}
		});
		
	} catch (e) {
		alert(e);
	}

	
	myDataTableD.insertar = function(rows){
        try {
            if (Y.lang.isArray(rows)) {
                for (var j = 0; j < rows.length; j++) {
                    var m = rows[j];
                    try {
                        var oData = {};
                        
                        oData['sequence'] = m.sequence;
                        oData['description'] = m.description;
                        oData['commonname'] = m.commonname;
                        oData['scientificname'] = m.scientificname;
                        oData['modificado'] = false;
                        myDataTableD.addRow(oData, myDataTableD.getRecordSet().getLength());
                        myDataTableD.render();
                    } catch (e) {
                        alert("insertar:" + e.description+" "+x.message);
                    }
                }
                
            }
        } catch (x) {
            alert("insertar: " + x.description +" "+x.message);
            return false;
        }
    };
	
	
	
}